<template>
  <view class="user-container">
    <!-- 头像昵称区 -->
    <view class="top-box">
      <image :src="userInfo.avatarUrl" mode="" class="user-image"></image>
      <text class="user-name" @click="test">{{userInfo.nickName}}</text>
    </view>
    <!-- 面板区 -->
    <view class="plain-container">
      <!-- 第一个面板 -->
      <view class="plain-top">
        <view class="plain-top-item">
          <text>8</text>
          <view>
            收藏的店铺
          </view>
        </view>
        <view class="plain-top-item">
          <text>18</text>
          <view>
            收藏的商品
          </view>
        </view>
        <view class="plain-top-item">
          <text>81</text>
          <view>
            关注的商品
          </view>
        </view>
        <view class="plain-top-item">
          <text>84</text>
          <view>
            足迹
          </view>
        </view>
      </view>
      <!-- 第二个面板 -->
      <view class="plain-middle">
        <view class="plain-middle-title">
          我的订单
        </view>
        <view class="plain-middle-item">
          <image src="../../static/my-icons/icon1.png" mode="" class="plain-middle-item-image"></image>
          <text>待付款</text>
        </view>
        <view class="plain-middle-item">
          <image src="../../static/my-icons/icon2.png" mode="" class="plain-middle-item-image"></image>
          <text>待收货</text>
        </view>
        <view class="plain-middle-item">
          <image src="../../static/my-icons/icon3.png" mode="" class="plain-middle-item-image"></image>
          <text>退款/收款</text>
        </view>
        <view class="plain-middle-item">
          <image src="../../static/my-icons/icon4.png" mode="" class="plain-middle-item-image"></image>
          <text>全部订单</text>
        </view>
      </view>
      <!-- 第三个面板 -->
      <view class="plain-bottom">
        <view class="plain-bottom-item">
          <text> 收货地址</text>
          <uni-icons type="arrowright" size="16"></uni-icons>
        </view>
        <view class="plain-bottom-item">
          <text>联系客服</text>
          <uni-icons type="arrowright" size="14"></uni-icons>
        </view>
        <view class="plain-bottom-item" @click="logOut">
          <text>退出登录</text>
          <uni-icons type="arrowright" size="14"></uni-icons>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  import {
    mapState,
    mapMutations
  } from 'vuex'
  export default {
    computed: {
      ...mapState('modulesUser', ['userInfo'])
    },
    methods: {
      ...mapMutations('modulesUser', ['updateToken', 'updateAddress', 'updateUserInfo']),
      // 退出登录
      async logOut() {
        // 询问用户是否退出登录
        const [err, succ] = await uni.showModal({
          title: '提示',
          content: '确认退出登录吗？'
        }).catch(err => err)

        if (succ && succ.confirm) {
          // 用户确认了退出登录的操作
          // 需要清空 vuex 中的 userinfo、token 和 address
          this.updateUserInfo({})
          this.updateToken('')
          this.updateAddress({})
          uni.$showMsg('登出成功!')
        }
      }
    }
  }
</script>

<style lang="less">
  .user-container {
    height: 100%;
    background-color: #f4f4f4;

    .top-box {
      width: 100%;
      height: 400rpx;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      background-color: #bfa;

      .user-image {
        width: 180rpx;
        height: 180rpx;
        display: block;
        margin-bottom: 20rpx;
        border-radius: 50%;
      }

      .user-name {
        font-size: 14px;
      }
    }

    .plain-container {
      width: auto;
      padding: 30rpx;
      position: relative;
      top: -50rpx;

      .plain-top {
        background-color: white;
        border-radius: 10rpx;
        display: flex;
        justify-content: space-evenly;
        height: 100rpx;
        margin-bottom: 20rpx;

        .plain-top-item {
          justify-content: space-evenly;
          display: flex;
          flex-direction: column;
          text-align: center;
          font-size: 13px;
        }
      }

      .plain-middle {
        display: flex;
        flex-wrap: wrap;
        height: 250rpx;
        background-color: white;
        justify-content: space-evenly;
        margin-bottom: 20rpx;
        border-radius: 10rpx;

        .plain-middle-title {
          width: 100%;
          height: 90rpx;
          line-height: 90rpx;
          border-bottom: 1px solid #f4f4f4;
          margin-left: 20rpx;
        }

        .plain-middle-item {
          width: 20%;
          display: flex;
          flex-direction: column;
          text-align: center;
          align-items: center;
          font-size: 14px;


          .plain-middle-item-image {
            width: 70rpx;
            height: 70rpx;
          }
        }
      }

      .plain-bottom {
        background-color: white;
        border-radius: 10rpx;

        .plain-bottom-item {
          width: auto;
          padding: 0 20rpx;
          height: 80rpx;
          display: flex;
          align-items: center;
          justify-content: space-between;
          font-size: 14px;
        }
      }

    }

  }
</style>
